﻿<%@ Page Title="店铺深度" Language="C#" MasterPageFile="~/master/m.master" %>

<script runat="server"></script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
<link href="../assets/css/plugins/footable/footable.core.css" rel="stylesheet">
<link href="../assets/css/shelf/base.css" rel="stylesheet">
<link href="../assets/css/plugins/webuploader/webuploader.css" rel="stylesheet" />
<link href="../assets/img/validate/validate.css" rel="stylesheet">


<style type="text/css">
.system-box .right-side {width: 100%;}
.condition, .condition-title {border-bottom: 1px solid #dfdfdd;}
#tbSize td {text-align: center;}
#tbSize td input {text-align: center;width: 100%;}
.form-group label{max-width: 70px;margin-left: 15px;padding-left: 5px;padding-right: 5px;}
#FirstTr td input{ padding-left: 2px;padding-right: 2px;}
#MinTr td input{ padding-left: 2px;padding-right: 2px;}
@media (min-width: 750px) { .modal-dialog{ width: 750px;}}

</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="main" runat="Server">
 <div class="system-box"> 
   <div class="right-side"> 
    <div class="btns-container"> 
     <div class="modal inmodal" id="addWindow" tabindex="-1" role="dialog" aria-hidden="true"> 
      <div class="modal-dialog"> 
       <div class="modal-content animated bounceInRight"> 
        <div class="modal-header"> 
         <span class="editTitle"></span> 
         <button type="button" class="close" data-dismiss="modal"> <span aria-hidden="true">&times;</span> <span class="sr-only">关闭</span> </button> 
        </div> 
        <div id="message" style="display: none"></div> 
        <div class="modal-body clearfix"> 
         <form class="form-horizontal"> 
          <div class="form-group"> 
           <label for="popCompanyID" class="col-sm-2 control-label">公司编码</label> 
           <div class="col-sm-10"> 
            <input type="text" id="popCompanyID" name="popCompanyID" placeholder="KM" class="form-control" readonly="readonly" value="KM" /> 
           </div> 
          </div> 
          <div class="form-group"> 
           <label for="popShop" class="col-sm-2 control-label">店&nbsp;&nbsp;铺:</label> 
           <div class="col-sm-10"> 
            <input type="text" id="popShop" name="popShop" placeholder="请输入店铺代码或名称" datacol="yes" err="店铺" checkexpession="NotNull" class="form-control required" autocomplete="off" /> 
           </div> 
          </div> 
          <div class="form-group"> 
           <label for="popKindId" class="col-sm-2 control-label">类&nbsp;&nbsp;型:</label> 
           <div class="col-sm-10"> 
            <select class="form-control" id="popKindId" name="popKindId"></select> 
           </div> 
          </div> 
          <div class="form-group"> 
           <label for="popModelId" class="col-sm-2 control-label">品&nbsp;&nbsp;类:</label> 
           <div class="col-sm-10"> 
            <select class="form-control" id="popModelId" name="popModelId" datacol="yes" checkexpession="MustSelect" err="品类"><option value="">---请选择---</option></select> 
           </div> 
          </div>
            <div class="form-group"> 
           <label for="popItemId" class="col-sm-2 control-label">小品类:</label> 
           <div class="col-sm-10"> 
            <select class="form-control" id="popItemId" name="popItemId" datacol="yes" checkexpession="MustSelect" err="小品类"><option value="">---请选择---</option></select> 
           </div> 
          </div>
          <div class="form-group"> 
           <label for="popSizeTypeFlag" class="col-sm-2 control-label">尺码类型:</label> 
           <div class="col-sm-10"> 
            <select class="form-control" id="popSizeTypeFlag" name="popSizeTypeFlag" datacol="yes" checkexpession="MustSelect" err="尺码类型"></select> 
           </div>
          </div>
          <div class="form-group"> 
           <label for="popSizeLength" class="col-sm-2 control-label">尺码长度:</label> 
           <div class="col-sm-10"> 
            <select class="form-control" id="popSizeLength" name="popSizeLength" datacol="yes" checkexpession="MustSelect" err="尺码长度">
                <option value="">---请选择---</option>
                <option value="1码">1码</option>
                <option value="2码">2码</option>
                <option value="3码">3码</option>
                <option value="4码">4码</option>
                <option value="5码">5码</option>
                <option value="6码">6码</option>
                <option value="7码">7码</option>
                <option value="8码">8码</option>
                <option value="9码">9码</option>
                <option value="10码">10码</option>
            </select> 
           </div>
          </div>
          <div class="form-group"> 
           <label for="tbSize" class="col-sm-2 control-label"><br />首配深度:<br /><br />最低深度:
           </label>
           <div class="col-sm-10"> 
            <table id="tbSize"> 
             <thead> 
              <tr id="ThTr">
                  <td>X</td>
                  <td>M</td>
              </tr> 
             </thead> 
             <tbody> 
              <tr id="FirstTr">
    <%--              <td><input class="td1 form-control" value="1" /></td>
                  <td><input class="td2 form-control" value="2" /></td> --%>
              </tr> 
                <tr id="MinTr">
<%--                  <td><input class="td1 form-control" value="1" /></td>
                  <td><input class="td2 form-control" value="2" /></td> --%>
              </tr> 
             </tbody> 
            </table> 
           </div> 
          </div> 
         </form> 
        </div> 
        <div class="modal-footer"> 
         <button type="button" id="addModuleBtn" class="btn btn-primary">保存</button> 
         <button type="button" id="closeAddBox" class="btn btn-white" data-dismiss="modal">关闭</button> 
        </div> 
       </div> 
      </div> 
     </div> 
    </div> 
    <div class="condition clearfix"> 
     <label>类别：</label> 
     <select class="form-control input-w90" id="search-KindID"> <option value="">请选择</option> </select> 
     <label>品类：</label> 
     <select class="form-control input-w90" id="search-ModelID"> <option value="">请选择</option> </select>
     <label>小品类：</label> 
     <select class="form-control input-w90" id="search-ItemID"> <option value="">请选择</option> </select> 
     <label>店铺&nbsp;&nbsp;</label> 
     <input class="form-control input-w155" id="search-Shop" placeholder="输入店铺名称或编号" /> 
    </div> 
    <div class="right-content-box"> 
     <div class="ibox-content"> 
      <table class="footable table table-stripped table-list loadTable"> 
       <thead></thead> 
       <tbody id="pageList"></tbody> 
      </table> 
     </div> 
    </div> 
    <div class="pageControl"></div> 
   </div> 
  </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="footer" runat="Server">
    <script src="../assets/js/jquery-ui-1.10.4.min.js"></script>
    <script src="../assets/img/validate/learunui-validator.js"></script>
    <script src="../assets/js/page/pageControl.js"></script>
    <script src="../assets/js/page/rScroll.js"></script>
    <script src="../assets/js/page/tableControl.js"></script>
    <script src="../assets/js/plugins/webuploader/webuploader.min.js"></script>
    <script src="../assets/js/framework.js"></script>
    <script src="../assets/js/plugins/bootstrap-typeahead/bootstrap-typeahead.js"></script>

    <script>
        var _CompanyID = null;
        var _ShopID = null;
        var _ShopName = null;
        var _KindID = null;
        var _KindName = null;
        var _ModelID = null;
        var _ModelName = null;
        var _ItemID = null;
        var _ItemName = null;
        var _SizeTypeFlag = null;
        var _SizeLength = null;
        var _FirstDCQty = null;
        var _MinQty = null;

        var GetDetail = function (isReadonly) {
            //加上*号
            $('#popShop').removeClass('required');
            $('#popFirstDCQty').addClass('required');
            //设置只读
            //$("#popCompanyID").attr('readonly', 'readonly');
            $("#popShop").attr('readonly', 'readonly');
            //$("#popFirstDCQty").removeAttr('readonly');
            //禁止改变选择
            $("#popKindId").attr('disabled', 'disabled');
            $("#popModelId").attr('disabled', 'disabled');
            $("#popItemId").attr('disabled', 'disabled');
            $("#popSizeTypeFlag").attr('disabled', 'disabled');
            $("#popSizeLength").attr('disabled', 'disabled');

            layer.msg('玩命加载中……', { icon: 16, shade: 0.5, time: 0, maxWidth: 200 });
            Y.API2('DCBasModelMinQty', "GetDetail",
                {
                    CompanyID: "KM",
                    ShopID: _ShopID,
                    KindID: _KindID,
                    ModelID: _ModelID,
                    ItemID: _ItemID,
                    SizeTypeFlag: _SizeTypeFlag,
                    SizeLength: _SizeLength
                },
                function (data) {
                    layer.closeAll('dialog');
                    if (data.Success == false) {
                        swal(data.Message, '', 'error');
                    } else {
                        $('#popCompanyID').val(data.CompanyID);
                        $('#popShop').val(data.ShopName);
                        $('#popKindId').val(data.KindID);
                        $('#popModelId').val(data.ModelID);
                        $('#popFirstDCQty').val(data.FirstDCQty);
                        $('#popSizeLength').val(data.SizeLength);

                        $('#popItemId').html('<option value="' + data.ItemID + '">' + data.ItemName + '</option>');
                        document.getElementById('popItemId').selectedIndex = 0;

                        $('#popSizeTypeFlag').html('<option value="' + data.SizeTypeFlag + '">' + data.SizeTypeFlag + '</option>');
                        document.getElementById('popSizeTypeFlag').selectedIndex = 0;

                        $('#popCompanyID').attr("original", data.CompanyID);
                        $('#popShop').attr("original", data.ShopID);
                        $('#popKindId').attr("original", data.KindID);
                        $('#popModelId').attr("original", data.ModelID);
                        $('#popItemId').attr("original", data.ItemID);
                        $('#popFirstDCQty').attr("original", data.FirstDCQty);
                        $('#popSizeTypeFlag').attr("original", data.SizeTypeFlag);
                        $('#popSizeLength').attr("original", data.SizeLength);


                        setSizes(data.SizeList, isReadonly);
                    }
                });
        }

        //获取最低深度列表
        var getSizeList = function (companyId, shopId, kindId, modelId, sizeTypeFlag, sizeLength) {
            Y.API2('DCBasModelMinQty', "GetSizeList",
                {
                    CompanyID: companyId,
                    ShopID: shopId,
                    KindID: kindId,
                    ModelID: modelId,
                    SizeTypeFlag: sizeTypeFlag,
                    SizeLength: sizeLength
                },
                function (data) {
                    layer.closeAll('dialog');
                    if (data.Success == false) {
                        swal(data.Message, '', 'error');
                    } else {
                        setSizes(data);
                    }
                });
        };

        var setSizes = function (data, isReadonly) {
            var thtd = "";
            var myFirstTrtd = "";
            var myMinTrtd = "";
            data.map(function (item, i) {
                thtd += '<td>' + item.SizeName + '</td>';
                myFirstTrtd += '<td>' + '<input type="number" class="td1 form-control" data-id="' + item.SizeID + '" value="' + (item.FirstDCQty == 0 ? "" : item.FirstDCQty) + '' + '">' + '</td>';
                myMinTrtd += '<td>' + '<input type="number" class="td1 form-control" data-id="' + item.SizeID + '" value="' + (item.MinQty == 0 ? "" : item.MinQty) + '' + '">' + '</td>';
            });

            $('#ThTr').html('' + thtd + '');
            $('#FirstTr').html('' + myFirstTrtd + '');
            $('#MinTr').html('' + myMinTrtd + '');

            if (isReadonly) {
                $('#FirstTr td input').attr('readonly', 'readonly');
                $('#MinTr td input').attr('readonly', 'readonly');
            } else {
                $('#FirstTr td input').removeAttr('readonly');
                $('#MinTr td input').removeAttr('readonly');
            }
        }


        $('document').ready(function () {
            //模块ID
            var ModuleID = Y.getUrlParam("ModuleID");
            //当前页数
            var page = 1;
            commonUtil.loadBtnList(ModuleID, function () {
                $('#editBtn').attr("disabled", "disabled");
                $('#btnDetail').attr("disabled", "disabled");
                rScroll();
            });

            var dataList = [];


            //处理表头
            if ($('.footable thead').children().size() == 0) {
                tableControl.initThead('.footable',
                [
                    {
                        trClass: '',
                        children: [
                            //{ tdText: '', c: 0, r: 0, tdHtml: '<input type="checkbox" id="checkAllPlan" />', tdId: '', tdClass: '' },
                            { tdText: '公司编码', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'hide' },
                            { tdText: '店铺ID', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'hide' },
                            { tdText: '店铺名称', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                            { tdText: '类别ID', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'hide' },
                            { tdText: '类别名称', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                            { tdText: '品类ID', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'hide' },
                            { tdText: '品类名称', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                            { tdText: '小品类ID', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'hide' },
                            { tdText: '小品类名称', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                            { tdText: '尺码类型', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                            { tdText: '尺码长度', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                            { tdText: '首配深度', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' },
                            { tdText: '最低深度', c: 0, r: 0, tdHtml: '', tdId: '', tdClass: '' }
                        ]
                    }
                ]);
            }

            //初始化下拉框
            commonUtil.bindGetDropDownList(['#search-KindID', '#popKindId'], 1); 
            commonUtil.bindGetDropDownList(['#search-ModelID', '#popModelId'], 4);

            $(document).on("change", "#search-ModelID", function () {
                $("#search-ItemID").html('<option value="">请选择</option>');
                if ($(this).val() == "") {
                    return;
                }

                commonUtil.bindDropDownItem(['#search-ItemID'], $(this).val()); //小品类
            });

            $(document).on("change", '#popModelId', function () {
                $("#search-ItemID").html('<option value="">请选择</option>');
                if ($(this).val() == "") {
                    return;
                }

                $('#popItemId').empty();
                $('#popItemId').html("");
                commonUtil.bindDropDownItem(['#popItemId'], $(this).val()); //小品类
            });



            var pageList = [];
            var loadList = function () {
                $('#editBtn').attr('disabled', 'disabled');
                $('#btnDetail').attr('disabled', 'disabled');

                var kindId = $('#search-KindID').val();
                var modelId = $('#search-ModelID').val();
                var itemId = $('#search-ItemID').val();
                var shop = $('#search-Shop').val().trim();

                pageControl.init('DCBasModelMinQty', 'GetList', {
                    KindID: kindId,
                    ModelID: modelId,
                    ItemID: itemId,
                    Shop: shop,
                    Page: page,
                    Size: 50,
                    needLayer: true,
                    alwaysCallBack: function () {
                        $('#pageList').empty();
                    }
                }, function (result) {
                    pageList = [];
                    page = result.page;
                    var tBody = [];
                    if (!Y.checkNull(result.data)) {
                        if (result.data.Items.length > 0) {
                            dataList = result.data.Items;
                            result.data.Items.map(function (item, i) {
                                pageList.push(item);
                                var tempTr = {
                                    trClass: (i % 2 == 0 ? 'gradeX footable-even' : 'gradeX footable-odd'),
                                    children: [
                                        //{ tdText: '', c: 0, r: 0, tdHtml: '<input type="checkbox" class="checkPlan" data-index="' + i + '" />', tdId: '', tdClass: '' },
                                        { tdText: (item.CompanyID || ''), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'CompanyID hide' },
                                        { tdText: (item.ShopID || ''), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'hide ShopID' },
                                        { tdText: (item.ShopName || ''), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'ShopName' },
                                        { tdText: (item.KindID || ''), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'hide KindID' },
                                        { tdText: (item.KindName || ''), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'KindName' },
                                        { tdText: (item.ModelID || ''), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'ModelID hide' },
                                        { tdText: (item.ModelName || ''), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'ModelName' },
                                        { tdText: (item.ItemID || ''), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'ItemID hide' },
                                        { tdText: (item.ItemName || ''), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'ItemName' },
                                        { tdText: (item.SizeTypeFlag || ''), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'SizeTypeFlag' },
                                        { tdText: (item.SizeLength || ''), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'SizeLength' },
                                        { tdText: (item.FirstDCQtySum || ''), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'FirstDCQtySum' },
                                        { tdText: (item.MinQtySum || ''), c: 0, r: 0, tdHtml: '', tdId: '', tdClass: 'MinQtySum' },
                                        // { tdText: '', c: 0, r: 0, tdHtml: '<div class="stepper-widget"><button type="button" class="js-qty-down btn btn-danger">-</button><input type="text" class="js-qty-input form-control FirstDCQty" value="' + item.FirstDCQty + '" /><button type="button" class="js-qty-up btn btn-primary">+</button></div>', tdId: '', tdClass: '' }
                                    ]
                                };
                                tBody.push(tempTr);
                            });
                        }
                        rScroll();
                    }
                    tableControl.initTbody('.footable', (tBody.length > 0 ? tBody : null), 13, null);
                });
            }

            var resetInput = function () {
                $('#popCompanyID').val("KM");
                $("#popShop").val("");
                $("#popFirstDCQty").val("");
                $('#popSizeTypeFlag').empty();
                //$('#popSizeLength').empty();
                $('#popItemId').empty();
                $('#FirstTr').html("");
                $('#MinTr').html("");
                $('#ThTr').html("");

                $('#popCompanyID').removeAttr("original");
                $('#popShop').removeAttr("original");
                $('#popKindId').removeAttr("original");
                $('#popModelId').removeAttr("original");
                $('#popItemId').removeAttr("original");
                $('#popSizeTypeFlag').removeAttr("original");
                $('#popSizeLength').removeAttr("original");

                document.getElementById('popModelId').selectedIndex = 0;
                document.getElementById('popKindId').selectedIndex = 0;
                document.getElementById('popItemId').selectedIndex = 0;
                document.getElementById('popSizeLength').selectedIndex = 0;
            };

            //选中记录
            $('#pageList').on('click', 'tr', function () {
                _CompanyID = $(this).find('.CompanyID').text();
                _ShopID = $(this).find('.ShopID').text();
                _ShopName = $(this).find('.ShopName').text();
                _KindID = $(this).find('.KindID').text();
                _KindName = $(this).find('.KindName').text();
                _ModelID = $(this).find('.ModelID').text();
                _ModelName = $(this).find('.ModelName').text();
                _ItemID = $(this).find('.ItemID').text();
                _ItemName = $(this).find('.ItemName').text();
                _SizeTypeFlag = $(this).find(".SizeTypeFlag").text();
                _SizeLength = $(this).find(".SizeLength").text();
                _FirstDCQty = $(this).find('.FirstDCQtySum').val();
                _MinQty = $(this).find('.MinQtySum').val();

                console.log(_ShopID + "\r\n" + _ShopName + "\r\n" + _KindID + "\r\n" + _KindName + "\r\n" + _ModelID + "\r\n" + _ModelName + "\r\n" + _ItemID + "\r\n" + _ItemName + "\r\n" + _SizeTypeFlag + "\r\n" + _SizeLength + "\r\n" + _FirstDCQty + "\r\n" + _MinQty);

                if (!Y.checkNull(_ModelID)) {
                    $('#editBtn').removeAttr('disabled');
                    $('#btnDetail').removeAttr('disabled');
                }

                $('.footable tr').removeClass('check');
                $(this).addClass('check');
            }); 

            //自动填充(商店)
            $('#popShop').typeahead({
                source: function (query, process) {
                    var parameter = { query: query };
                    Y.API2('DwShop', 'GetShopDownList2', {
                        Shop: $('#popShop').val()
                    }, function (data) {
                        if (data.Success == false) {
                            swal(data.Message, '', 'error');
                        } else {
                            $('#popShop').removeAttr("ShopID");
                            var results = data.map(function (item) {
                                return JSON.stringify(item);
                            });
                            process(results);
                        }
                    });
                },
                highlighter: function (item) {
                    var item = JSON.parse(item);
                    return '名称：' + item.ShopName + '　编号：' + item.ShopCode;
                },
                updater: function (item) {
                    var item = JSON.parse(item);
                    $('#popShop').val(item.ShopName);
                    //$('#popShop').attr("ShopCode", item.ShopCode);
                    $('#popShop').attr("ShopID", item.ShopID);

                    var companyId = $('#popCompanyID').val();
                    var shopId = $('#popShop').attr("ShopID");
                    var kindId = $('#popKindId').val();
                    var modelId = $('#popModelId').val();
                    var sizeTypeFlag = $('#popSizeTypeFlag').val();
                    var sizeLength = $('#popSizeLength').val();

                    if (companyId != "" && shopId != "" && shopId != undefined && kindId != "" && modelId != "" && modelId != "0" && sizeTypeFlag != "") {
                        getSizeList(companyId, shopId, kindId, modelId, sizeTypeFlag, sizeLength);
                    } else {
                        //console.log("获取了店铺，但是填写不完整，不获取最低深度");
                    }
                    return item.ShopName;
                }
            });

            //查询按钮ok
            $('.btns-container').on('click', '#btn-search', function () {
                page = 1;
                loadList();
            });

            //新增按钮
            $('.btns-container').on('click', '#addBtn', function () {
                $('.editTitle').text('新增配置');
                $('#addModuleBtn').show();

                //加上*号
                $('#popShop').addClass('required');
                $('#popFirstDCQty').addClass('required');
                //去掉只读
                //$("#popCompanyID").attr('readonly', 'readonly');
                $("#popShop").removeAttr('readonly');
                $("#popFirstDCQty").removeAttr('readonly');
                //去掉禁止
                $('#popKindId').removeAttr('disabled');
                $('#popModelId').removeAttr('disabled');
                $('#popItemId').removeAttr('disabled');
                $('#popSizeTypeFlag').removeAttr('disabled');
                $('#popSizeLength').removeAttr('disabled');


                $('#popShop').removeAttr('ShopID');
                resetInput();
            });

            //编辑按钮
            $('.btns-container').on('click', '#editBtn', function () {
                $('.editTitle').text('编辑配置');
                $('#addModuleBtn').show();
                resetInput();

                if (_ShopName == "" || _ShopID == "") {
                    swal("参数异常，请刷新页面重试", '', 'error');
                    return false;
                }

                GetDetail(false);
            });

            //明细按钮
            $('.btns-container').on('click', '#btnDetail', function () {
                $('.editTitle').text('查看明细');
                $('#addModuleBtn').hide();

                if (_ShopName == "" || _ShopID == "") {
                    swal("参数异常，请刷新页面重试", '', 'error');
                    return false;
                }

                GetDetail(true);
            });

            //弹窗的保存操作
            $('#addModuleBtn').click(function () {
                if (!CheckDataValid('.form-horizontal')) {
                    return false;
                }
                var action = "";
                var successText = "";
                if ($('.editTitle').text() == '新增配置') {
                    action = "Insert";
                    successText = '新增成功';

                    var modelId = $('#popShop').attr('ShopID');
                    if (modelId == '' || modelId == undefined) {
                        swal("请先在店铺搜索的下拉列表选择店铺", '', 'error');
                        return false;
                    }
                }
                else {
                    action = "Update";
                    successText = '编辑成功';
                }

                var isOver = false;
                var sizeList = [];
                var firstSizeList = $('#FirstTr td input');
                var minSizeList = $('#MinTr td input');
                for (var i = 0; i < firstSizeList.length; i++) {
                    //不同时为空就行
                    var first = firstSizeList.eq(i);
                    var min = minSizeList.eq(i);

                    if ((first.val() != "" || min.val() != "") && (first.val() >0 || min.val() >0)) {
                        var tmp = {};
                        tmp.SizeID = first.attr('data-id');
                        tmp.FirstDCQty = first.val();
                        tmp.MinQty = min.val();
                        if (tmp.FirstDCQty < 0 || tmp.FirstDCQty > 999 || tmp.MinQty < 0 || tmp.MinQty > 999) {
                            isOver = true;
                            break;
                        } else {
                            sizeList.push(tmp);
                        }
                    }
                }

                if (isOver) {
                    swal("首配深度和最低深度都必须在区间[0,999]之间", '', 'error');
                    return false;
                }

                if (sizeList.length == 0) {
                    swal("首配深度和最低深度不能同时不填，也不能同时为0", '', 'error');
                    return false;
                }

                var sizeNot0 = [];
                var firstInput = $('#FirstTr').find('input');
                var minInput = $('#MinTr').find('input');
                for (var i = 0; i < firstInput.length; i++) {
                    var a = firstInput.eq(i).val();
                    var b = minInput.eq(i).val();
                    if ((a != 0 && a != "") || (b != 0 && b != "")) {
                        sizeNot0.push(a);
                    }
                }

                if (sizeNot0.length != $('#popSizeLength').val().replace('码','')) {
                    swal("首配和最低深度所填尺码的并集总数必须等于尺码长度", '', 'error');
                    return false;
                }

                layer.msg('玩命加载中……', { icon: 16, shade: 0.5, time: 0, maxWidth: 200 });
                Y.API2('DCBasModelMinQty',
                    action,
                    {
                        CompanyID: $('#popCompanyID').val(),
                        Shop: $('#popShop').val(),
                        KindID: $("#popKindId").val(),
                        ModelID: $("#popModelId").val(),
                        ItemID: $("#popItemId").val(),
                        SizeTypeFlag: $('#popSizeTypeFlag').val(),
                        SizeLength: $('#popSizeLength').val(),
                        FirstDCQty: $("#popFirstDCQty").val(),
                        OriginalCompanyID: $('#popCompanyID').attr("original"),
                        OriginalShop: $('#popShop').attr("original"),
                        originalKindID: $("#popKindId").attr("original"),
                        originalModelID: $("#popModelId").attr("original"),
                        OriginalItemID: $("#popItemId").attr("original"),
                        originalSizeTypeFlag: $('#popSizeTypeFlag').attr("original"),
                        originalSizeLength: $('#popSizeLength').attr("original"),
                        SizeList: sizeList

                }, function (data) {
                    layer.closeAll('dialog');
                    if (data.Success == false) {
                        swal(data.Message, '', 'error');
                    } else {
                        swal(successText, '', 'success');
                        //关闭新建  or 编辑框
                        $('#closeAddBox').click();
                        loadList();
                    }
                });
            });





            //导入
            $(".btns-container").on("click", '#importBtn', function () {
                $.ImportExcelTemplate({
                    filetype: ['DCBASMODELMINQTY'],
                    filename: [
                        { name: '店铺深度', state: null }
                    ],
                    action: 'ImportTemplate',
                    after: function () {
                        loadList();
                    }
                });
            });

            //选择品类>级联获取尺码类型、最低深度
            $("#popModelId").change(function () {
                var companyId = $('#popCompanyID').val();
                var shopId = $('#popShop').attr("ShopID");
                var kindId = $('#popKindId').val();
                var modelId = $(this).val();

                Y.API2('DCBasModelMinQty', "GetSizeTypeFlag", { CompanyID: companyId, ModelID: modelId }, function (data) {
                    layer.closeAll('dialog');
                    if (data.Success == false) {
                        swal(data.Message, '', 'error');
                    } else {
                        //获取尺码类型
                        $('#popSizeTypeFlag').empty();
                        var option = "";
                        data.map(function (item, i) {
                            option += '<option value="' + item.SizeTypeFlag + '">' + item.SizeTypeFlag + '</option>';
                        });
                        $('#popSizeTypeFlag').html(option);
                        document.getElementById('popSizeTypeFlag').selectedIndex = 0;
                        var sizeTypeFlag = $('#popSizeTypeFlag').val();
                        var sizeLength = $('#popSizeLength').val();

                        if (companyId != "" && shopId != "" && shopId != undefined && kindId != "" && modelId != "" && modelId != "0" && sizeTypeFlag != "") {
                            getSizeList(companyId, shopId, kindId, modelId, sizeTypeFlag, sizeLength);
                        }
                    }
                });
            });


            //选择尺码类型>级联获取最低深度
            $("#popSizeTypeFlag").change(function () {
                var companyId = $('#popCompanyID').val();
                var shopId = $('#popShop').attr("ShopID");
                var kindId = $('#popKindId').val();
                var modelId = $('#popModelId').val();
                var sizeTypeFlag = $('#popSizeTypeFlag').val();
                var sizeLength = $('#popSizeLength').val();

                if (companyId != "" && shopId != "" && shopId != undefined && kindId != "" && modelId != "" && modelId != "0" && sizeTypeFlag != "" && sizeLength != "") {
                    getSizeList(companyId, shopId, kindId, modelId, sizeTypeFlag, sizeLength);

                }
            });

            //默认打开就加载数据
            loadList();
        });
    </script>
</asp:Content>

